<template>
  <!-- 诊疗项目增加 -->
  <div id="app">
    <!-- 设置顶部导航栏 -->
    <mt-header :title="title">
      <mt-button icon="back" @click="goBack" slot="left">返回</mt-button>
      <mt-button slot="right" @click="goHome">
        <img
          src="../../assets/images/home.png"
          height="20"
          width="20"
          slot="icon"
          style="margin-top: 5px"
        />
      </mt-button>
    </mt-header>
    <van-form @submit="onSubmit">
      <van-field
        v-model="name"
        name="诊疗项目名称"
        label="诊疗项目名称"
        placeholder="诊疗项目名称"
        :rules="[{ required: true, message: '请填写诊疗项目名称' }]"
      />
      <van-field
        v-model="price"
        name="诊疗项目价格"
        label="诊疗项目价格"
        placeholder="诊疗项目价格"
        :rules="[{ required: true, message: '请填写诊疗项目价格' }]"
      />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit"
          >提交</van-button
        >
      </div>
    </van-form>
  </div>
</template>

<script>
import { Toast } from "vant";
export default {
  name: "HospitalAppStaffManage",

  data() {
    return {
      title: "添 加 诊 疗 项 目",
      name: "",
      price: "",
      id: "",
    };
  },

  mounted() {},

  created() {
    //有id则先获取id
    this.id = this.$route.query.id;
    if (this.id) {
      this.title = "修 改 诊 疗 项 目";
    }
    console.log(this.id);
  },

  methods: {
    //提交按钮
    onSubmit() {
      this.$http
        .post("treat-type", {
          id: this.id,
          name: this.name,
          price: this.price,
        })
        .then((res) => {
          console.log(res);
          Toast("添加成功");
          setTimeout(() => {
            this.$router.push({
              path: "./diagnostic",
            });
          }, 800);
        });
    },
    goBack() {
      this.$router.push({
        path: "./diagnostic",
      });
    },
    goHome() {
      this.$router.push({
        path: "./index",
      });
    },
  },
};
</script>

<style lang="scss" scoped>
</style>